home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_087 / movepointer / movepointer.c < prev   
C/C++ Source or Header  |  1992-05-06  |  5KB  |  182 lines

  1.  
  2. /*
  3.     This little utility was written by the German Softcracking Group 9
  4.     and intentionally left in the PUBLIC DOMAIN.
  5.  
  6.    Feel free to copy the program and this Lattice-C source file, but
  7.    keep the name of the autor in it.
  8.  
  9.                      G.S.G. 9 (Cewy)  10-May-87
  10.  
  11.    If you'll do any changes (fix bugs or else) leave the new source
  12.    (Lattice only !) at the BBS-BOX called 'Barrel-Burst-Box' and a
  13.    message to me 'CEWY'. I'll check the box each week!
  14.  
  15.    Phone : (Germany) 06151/ 595240    (300 8N1 or 1200 8N1)
  16.  
  17. */
  18.  
  19. /* executable (batch) file :
  20.   .key name
  21.   .def name MovePointer
  22.   stack 30000
  23.   lc -v <name>
  24.   BLink FROM LIB:c.o+<name>.o TO <name> LIBRARY LIB:lc.lib+LIB:amiga.lib NODEBUG
  25. */
  26.  
  27. /* -------------------------- include section ------------------------ */
  28.  
  29. #include <stdio.h>
  30. #include <intuition/intuition.h>
  31. #include <devices/input.h>
  32.  
  33. /* -------------------- global variable section ---------------------- */
  34.  
  35. struct   IntuitionBase  *IntuitionBase = NULL; 
  36. struct   InputEvent     MyEvent;
  37. struct   IOStdReq       *MyRequest = NULL, *CreateStdIO();
  38. struct   MsgPort        *MyPort = NULL,    *CreatePort ();
  39.  
  40. /* ---------------------- local function section --------------------- */
  41. /* DESCRIPTION :
  42.       print the usage of the program, so the user knows how to handle it.
  43.    BUGS :
  44.       none.
  45.    COMMENT :
  46.       uses puts instead of printf, 'cause puts is much shorter.
  47. */
  48. void Usage()
  49. {
  50.    puts ("Usage: MovePointer NewXpos [NewYpos [R(elative) K(lick)]]");
  51.    puts ("written by G.S.G. 9 in May '87");
  52.    exit (20);
  53. }
  54.  
  55. /* ======== */
  56. /* DESCRIPTION :
  57.       Close everything opened by me or the system
  58.    BUGS :
  59.       none.
  60.    COMMENT :
  61.       none.
  62. */
  63. void CleanUp ()
  64. {
  65.    /* say good bye */
  66.    if (MyRequest) {
  67.       if (MyRequest-> io_Device) CloseDevice (MyRequest);
  68.       DeleteStdIO (MyRequest);
  69.    }
  70.    if (MyPort) DeletePort (MyPort);
  71.  
  72.    /* close the opened library */
  73.    if (IntuitionBase) CloseLibrary (IntuitionBase);
  74.  
  75. }
  76.  
  77. /* ======== */
  78. /* DESCRIPTION :
  79.       Die. Call Cleanup to leave the system in peace.
  80.    BUGS :
  81.       none.
  82.    COMMENT :
  83.       none.
  84. */
  85. void abort (value)
  86. int value;
  87. {
  88.    CleanUp ();
  89.    exit (value);
  90. }
  91.  
  92. /* ----------------------- main program section ----------------------- */
  93. /* DESCRIPTION :
  94.       Find the WorkbenchScreen and tell intuition that the mouse did move
  95.    BUGS :
  96.       none. (?)
  97.    COMMENT :
  98.       none.
  99. */
  100.  
  101. main (argc,argv)
  102. int argc;
  103. char *argv[];
  104. {
  105.    BOOL  Relative;
  106.    int   Mouseklick;
  107.  
  108.    /* check the number of arguments */
  109.    if (argc <3 || argc >5 || *argv[1] == '?') Usage ();
  110.  
  111.    Relative = FALSE;
  112.    Mouseklick = 0;
  113.  
  114.    while (argc > 3 && *argv[3])
  115.       switch (*argv[3]++) {
  116.          case 'r' : case 'R' : Relative = TRUE; break;
  117.          case 'k' : case 'K' : Mouseklick++; break;
  118.          default  : Usage ();
  119.       }
  120.  
  121.  
  122.    /* open the intuition */
  123.    if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary
  124.          ("intuition.library",0))) abort (100);
  125.  
  126.    /* open the needed ports and IOs */
  127.    if (!(MyPort    = CreatePort (0,0)))     abort (110);
  128.    if (!(MyRequest = CreateStdIO (MyPort))) abort (120);
  129.  
  130.    if (OpenDevice ("input.device",0,MyRequest,0) ) abort (130);
  131.  
  132.    MyRequest -> io_Command = IND_WRITEEVENT;
  133.    MyRequest -> io_Flags   = 0;
  134.    MyRequest -> io_Length  = sizeof (struct InputEvent);
  135.    MyRequest -> io_Data    = (APTR) &MyEvent;
  136.  
  137.    MyEvent.ie_NextEvent          = NULL;            /* no further event*/
  138.    MyEvent.ie_Class              = IECLASS_RAWMOUSE;
  139.    MyEvent.ie_TimeStamp.tv_secs  = 0;
  140.    MyEvent.ie_TimeStamp.tv_micro = 0;
  141.    MyEvent.ie_Code               = IECODE_NOBUTTON;
  142.    MyEvent.ie_Qualifier          = IEQUALIFIER_RELATIVEMOUSE;
  143.  
  144.    if (!Relative) {
  145.       MyEvent.ie_Y   = -574;  /* move to origin, biggest screen    */
  146.       MyEvent.ie_X   = -704;  /* see morerows (FISH 54)           */
  147.       DoIO (MyRequest);       /* tell intuition what you wanna do */
  148.    }
  149.  
  150.    MyEvent.ie_Y   = (SHORT) atoi (argv[2]);
  151.    MyEvent.ie_X   = (SHORT) atoi (argv[1]);
  152.    DoIO (MyRequest);  /* tell intuition what you wanna do */
  153.  
  154.    for (; Mouseklick; Mouseklick--) {
  155.       MyRequest -> io_Command = IND_WRITEEVENT;
  156.       MyRequest -> io_Flags   = 0;
  157.       MyRequest -> io_Length  = sizeof (struct InputEvent);
  158.       MyRequest -> io_Data    = (APTR) &MyEvent;
  159.  
  160.       MyEvent.ie_NextEvent          = NULL;            /* no further event*/
  161.       MyEvent.ie_Class              = IECLASS_RAWMOUSE;
  162.       MyEvent.ie_TimeStamp.tv_secs  = 0;
  163.       MyEvent.ie_TimeStamp.tv_micro = 0;
  164.       MyEvent.ie_Code               = IECODE_LBUTTON;
  165.       MyEvent.ie_X = 0;
  166.       MyEvent.ie_Y = 0;
  167.  
  168.       DoIO (MyRequest);
  169.       Delay (1);
  170.  
  171.       MyEvent.ie_Code =  IECODE_NOBUTTON;    /* hold down the button */
  172.       DoIO (MyRequest);
  173.       Delay (1);
  174.    }
  175.  
  176.    CleanUp (); /* close all things */
  177.  
  178.    /* say 'well done' the the system */
  179.    return (0);
  180. }
  181.  
  182.